package com.neu.web.controller.system;

import com.neu.common.core.controller.BaseController;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.neu.common.annotation.Log;
import com.neu.common.core.controller.BaseController;
import com.neu.common.core.domain.AjaxResult;
import com.neu.common.enums.BusinessType;
import com.neu.system.domain.NeuCity;
import com.neu.system.service.INeuCityService;
import com.neu.common.utils.poi.ExcelUtil;
import com.neu.common.core.page.TableDataInfo;

@RestController
@RequestMapping("/system/city")
@Api(tags = "城市接口")
public class NeuCityController extends BaseController {
    @Autowired
    private INeuCityService neuCityService;

    /**
     * 查询城市列表
     */
    @ApiOperation("获取城市列表")
    @PreAuthorize("@ss.hasPermi('system:city:list')")
    @GetMapping("/list")
    public TableDataInfo list(NeuCity neuCity)
    {
        startPage();
        List<NeuCity> list = neuCityService.selectNeuCityList(neuCity);
        return getDataTable(list);
    }

    /**
     * 导出城市列表
     */
    @ApiOperation("导出城市列表")
    @PreAuthorize("@ss.hasPermi('system:city:export')")
    @Log(title = "导出城市", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NeuCity neuCity)
    {
        List<NeuCity> list = neuCityService.selectNeuCityList(neuCity);
        ExcelUtil<NeuCity> util = new ExcelUtil<NeuCity>(NeuCity.class);
        util.exportExcel(response, list, "城市列表数据");
    }

    /**
     * 获取城市详细信息
     */
    @ApiOperation("获取城市信息")
    @PreAuthorize("@ss.hasPermi('system:city:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(neuCityService.selectNeuCityById(id));
    }

    /**
     * 新增城市
     */
    @ApiOperation("新增城市")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "city", value = "城市名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "alias", value = "城市别名", dataType = "String", dataTypeClass = String.class)
    })
    @PreAuthorize("@ss.hasPermi('system:city:add')")
    @Log(title = "新增城市", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NeuCity neuCity)
    {
        return toAjax(neuCityService.insertNeuCity(neuCity));
    }

    /**
     * 修改城市
     */
    @ApiOperation("修改城市")
    @PreAuthorize("@ss.hasPermi('system:city:edit')")
    @Log(title = "修改城市", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NeuCity neuCity)
    {
        return toAjax(neuCityService.updateNeuCity(neuCity));
    }

    /**
     * 删除城市列表
     */
    @ApiOperation("删除城市列表")
    @PreAuthorize("@ss.hasPermi('system:city:remove')")
    @Log(title = "删除城市", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(neuCityService.deleteNeuCityByIds(ids));
    }
}
